<template>
  <div @click="console.info('c')">
    <v-list subheader>
      <v-subheader>查询历史</v-subheader>
      <template v-for="(item,idx) in history">
        <v-divider :key="idx"></v-divider>
        <v-list-tile avatar :key="item.text" @click="clickHistoryLi(item.text)">
          <v-list-tile-content>
            <v-list-tile-title>
              {{item.text+' '}}<span class="grey--text text--lighten-1">{{getTypeName(item.type)}}</span>
            </v-list-tile-title>
          </v-list-tile-content>
        </v-list-tile>
      </template>
    </v-list>
  </div>
</template>
<script>
import utils from '../utils/commonUtils'
export default {
  props:['update'],
  data () {
    return {
      history: []
    }
  },
  beforeMount(){
    this.initHistory();
  },
  methods:{
    initHistory(){
      this.history = utils.searchHistory.getHistory();
    },
    clickHistoryLi(text){
      this.$emit('clickHistoryLi',text);
    },
    getTypeName(type){
      if(type==='5'){
        return '没有完全匹配的结果';
      }else{
        let info = this.$store.getters.wasteInfo(type);
        return info.name;
      }
    }
  },
  watch:{
    update(){
      this.initHistory();
    }
  }
}
</script>
<style lang="less" scoped>
</style>
